﻿(function () {
    appModule.controller('tenant.views.test.createOrEditTest', [
        '$scope', '$uibModal', '$uibModalInstance', 'abp.services.app.test', 'parameters',
        function ($scope, $uibModal, $uibModalInstance, testService, parameters) {
            var vm = this;
            vm.testComponentData = null;
            //所选行数据
            vm.rowData = parameters.rowData;
            vm.selectedRowId = parameters.testId
            //数据测试
            testService.getTestsAsync().success(function (result) {
                console.log('result:', result);
                vm.testComponentData = result.items;
            });
            //单选变量
            vm.testRadio = "key2";
            //多选变量
            vm.testCheckBox = {
                "key1": true //设置默认值
            };
            //下拉框配置
            vm.testDropdownBox = null;
            vm.selectedItem = null;
            var urlTest = "/api/services/app/test/"; //获取数据的地址
            var testDataSource = new kendo.data.DataSource({ //实例化数据源
                type: 'aspnetmvc-ajax', //请求类型
                transport: {
                    read: {//读取模式
                        url: urlTest + "KendoGetTests",
                        contentType: "application/json",
                        type: "POST"
                    },
                    parameterMap: function (options, operation) {
                        return JSON.stringify(options);
                    }
                },
                serverFiltering: true,
                schema: {
                    data: function (data) {
                        if (data.success == true && data.result !== null) {
                            vm.testDropdownBox = data.result.data;//请求获取的数据
                            if (vm.testDropdownBox.length == 0) {
                                vm.selectedItem = null;
                            }
                            return vm.testDropdownBox;
                        }
                        return {};
                    },
                },
                filter: {//过滤条件的配置
                    field: "",
                    operator: "",
                    value: {},
                    logic: "",
                    filters: [

                    ]
                }
            });
            vm.testTypesOptions = {
                dataSource: testDataSource,//数据源
                optionLabel: "选择类型",
                dataTextField: "value",//显示字段
                dataValueField: "key",//值
                //index: 0,//默认显示
                //autoBind: false,//预加载
                //template: '<span>#: data.surname ##: data.name #</span>',//自定义显示字段
                change: function (e) {//切换事件
                    //alert('select改变了');
                }
            };
            //时间控件配置
            vm.dateTimePickerOptions = {
                start: "year", //开始视图 参数有century世纪视图 decade十年视图 year年视图 month月视图
                depth: "year", //设置可以选择视图的深度, 参数有century世纪视图 decade十年视图 year年视图 month月视图
                format: "yyyy/MM/dd hh:mm tt",//要显示的格式
                value: new Date(),//默认值
                change: function () { //值改变时触发
                    var value = this.value();
                    console.log(value);
                }
            }
            //关闭模态框
            vm.cancel = function () {
                $uibModalInstance.dismiss();
            };
        }
    ]);
})();